package com.shop.technicalservice.dao.role.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.role.ControllersDao;
import com.shop.technicalservice.model.role.Controllers;

/**
 * A data access object (DAO) providing persistence and search support for
 * Controllers entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see org.rjb.pojo.ControllersDto
 * @author MyEclipse Persistence Tools
 */

public class ControllersDaoImpl extends HibernateDaoSupport implements ControllersDao{
	private static final Log log = LogFactory.getLog(ControllersDaoImpl.class);
	// property constants
	public static final String NAME = "name";
	public static final String PWD = "pwd";

	protected void initDao() {
		// do nothing
	}

	public Controllers save(Controllers transientInstance)  throws Exception{
		log.debug("saving Controllers instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Controllers persistentInstance) throws Exception {
		log.debug("deleting Controllers instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Controllers findById(java.lang.Integer id) throws Exception {
		log.debug("getting Controllers instance with id: " + id);
			Controllers instance = (Controllers) getHibernateTemplate().get(
					"org.rjb.Controllers", id);
			return instance;
	}

	public List findByExample(Controllers instance) {
		log.debug("finding Controllers instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value)  throws Exception{
		log.debug("finding Controllers instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Controllers as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByName(Object name)  throws Exception{
		return findByProperty(NAME, name);
	}

	public List findByPwd(Object pwd)  throws Exception{
		return findByProperty(PWD, pwd);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Controllers instances");
			String queryString = "from Controllers";
			return getHibernateTemplate().find(queryString);
	}

	public Controllers merge(Controllers detachedInstance)  throws Exception{
		log.debug("merging Controllers instance");
			Controllers result = (Controllers) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Controllers instance)  throws Exception{
		log.debug("attaching dirty Controllers instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Controllers instance) {
		log.debug("attaching clean Controllers instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re; 
		}
	}

	public static ControllersDaoImpl getFromApplicationContext(
			ApplicationContext ctx) {
		return (ControllersDaoImpl) ctx.getBean("ControllersDAO");
	}

}